package com.hq.door.dto;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.hq.door.pojo.TParent;
import com.hq.door.pojo.TRecords;
import com.hq.door.util.ExcelUtil;

/**
 * 前台刷卡记录
 * 作者：袁健宝
 * 日期：2017年2月12日 下午4:52:34
 */
public class RecordFrontDto {
	
	//查询参数
	private Date startDate;
	private Date endDate;
	private Integer pageNo;
	private Integer pageSize;
	private String type;	//类型（1-出校，2-进校，3-异常）
	//家长表
	private String mobile;		//家长手机号，唯一索引
	//学生表
	private String stuName;		//学生姓名
	//刷卡记录表
	private String recordDate;	//刷卡时间
	private String typeIO;		//进出校类型
	private String isException;	//是否异常记录
	
	public RecordFrontDto(){}
	
	public RecordFrontDto(Date startDate,Date endDate,String type, String mobile, String stuName,
			String recordDate, String typeIO, String isException) {
		this.startDate = startDate;
		this.endDate = endDate;
		this.type = type;
		this.mobile = mobile;
		this.stuName = stuName;
		this.recordDate = recordDate;
		this.typeIO = typeIO;
		this.isException = isException;
	}

	@Override
	public String toString() {
		return "ParentRecordFront [startDate" +startDate +",endDate=" + endDate + ",type=" + type + ", mobile=" + mobile
				+ ", stuName=" + stuName + ", recordDate=" + recordDate
				+ ", typeIO=" + typeIO + ", isException=" + isException + "]";
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getStuName() {
		return stuName;
	}

	public void setStuName(String stuName) {
		this.stuName = stuName;
	}

	public String getRecordDate() {
		return recordDate;
	}

	public void setRecordDate(String recordDate) {
		this.recordDate = recordDate;
	}

	public String getTypeIO() {
		return typeIO;
	}

	public void setTypeIO(String typeIO) {
		this.typeIO = typeIO;
	}

	public String getIsException() {
		return isException;
	}

	public void setIsException(String isException) {
		this.isException = isException;
	}

	/**
	 * 数据库对象 pojo转换成自定义类
	 * @param parent	
	 * @return
	 */
	public static RecordFrontDto writeRecord(TRecords trecord,String stuName){
		RecordFrontDto prf = null;
	    if (trecord != null){
	    	prf = new RecordFrontDto();
	    	prf.setStuName(stuName);	//学生姓名
	    	prf.setRecordDate(obj2Date(trecord.getCreateTime()));			//刷卡时间
	    	prf.setTypeIO(trecord.getInoutType().toString());				//进出校类型
	    	prf.setIsException(trecord.getIsException().toString());				//进出校类型
	    }
	    return prf;
    }
	
	/**
	 * 查询多条信息
	 * @param tparents
	 * @return
	 */
	public static List<RecordFrontDto> writeRecords(List<TRecords> trecords,String stuName){
		List<RecordFrontDto> prfs = new ArrayList<RecordFrontDto>();
		for (TRecords trecord : trecords) {
			RecordFrontDto prf = writeRecord(trecord,stuName);
			prfs.add(prf);
		}
		return prfs;
	}
	
	/**
	 * Long类型转成日期yyyy-MM-dd HH:mm:ss
	 * @param obj
	 * @return
	 */
	private static String obj2Date(Object obj){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String result = "";
		if(obj!=null){
			if(obj instanceof Long){
				result = sdf.format(new Date((long)obj));
			}else if(obj instanceof Timestamp){
				result = sdf.format(new Date(((Timestamp)obj).getTime()));
			}
		}
		return result;
	}
	
}
